home *** CD-ROM | disk | FTP | other *** search
Wrap
/* ResetHandler.e * * Warns the user if a keyboard reset has been triggered and allows the execution * of user-defined DOS commands at this point. * * © FtC of EfS 131195 * * v1.01: 151295 * * Changed the default behaviour to not display the (not really useful) requester * and to execute s:ShutDown.sequence instead. * * Changed the option "NoWarn" into "Warn" * * Cleaned up the docs * */ OPT PREPROCESS MODULE 'dos/dos','utility/tagitem','dos/rdargs','dos/dostags','devices/keyboard', 'commodities','libraries/commodities','exec/ports','exec/tasks','exec/io', 'exec/interrupts','exec/nodes','intuition/intuition','workbench/startup', 'icon','workbench/workbench' ENUM OK=0,RDA,BROKER,NOSIG OBJECT argvec shutdowncmd : PTR TO CHAR wait : PTR TO LONG warn ENDOBJECT OBJECT asmdata task : PTR TO tc signal ENDOBJECT RAISE RDA IF ReadArgs()=NIL, "LIB" IF OpenLibrary()=NIL, "DEV" IF OpenDevice()<>NIL, "MEM" IF CreateMsgPort()=NIL, BROKER IF CxBroker()=NIL PROC main() HANDLE DEF rda=0 : PTR TO rdargs, av : argvec, myname[33] : ARRAY OF CHAR, nb : PTR TO newbroker, broker=0 : PTR TO CHAR, -> well, it isn't, but it's considered a black box... cxport=0 : PTR TO mp, keyport=0 : PTR TO mp, keyreq=0 : PTR TO iostd, int=0 : PTR TO is, data=0 : PTR TO asmdata, signal=0,installed=0, msg : PTR TO CHAR, -> >same< rhd : PTR TO CHAR, dobj=0 : PTR TO diskobject, wb : PTR TO wbstartup, msgid, msgtype, running=TRUE, cxmask, recd, listen=TRUE, oldcd cxbase := 0 iconbase := 0 rhd := 'ResetHandler' IF GetProgramName(myname, 32) = 0 THEN myname := rhd cxbase := OpenLibrary('commodities.library', 37) iconbase := OpenLibrary('icon.library', 33) av.shutdowncmd := 'Execute S:Shutdown-Sequence' av.wait := [0] av.warn := FALSE IF wbmessage wb := wbmessage oldcd := CurrentDir(wb.arglist.lock) dobj := GetDiskObject(wb.arglist.name) IF dobj recd := FindToolType(dobj.tooltypes, 'SHUTDOWNCOMMAND') IF recd av.shutdowncmd := New(StrLen(recd) + 1) AstrCopy(av.shutdowncmd, recd) ENDIF recd := FindToolType(dobj.tooltypes, 'WAIT') IF recd THEN av.wait := NEW [Val(recd)] recd := FindToolType(dobj.tooltypes, 'WARN') IF recd THEN av.warn := TRUE FreeDiskObject(dobj) ENDIF CurrentDir(oldcd) ELSE rda := ReadArgs('ShutDownCommand,Wait/N,Warn/S', av, NIL) ENDIF IF av.shutdowncmd[] = 0 THEN av.shutdowncmd := NIL cxport := CreateMsgPort() nb := [NB_VERSION, 0, rhd, 'ResetHandler 1.01 by FtC of EfS', 'Warns the user in case of a reset', NBU_UNIQUE OR NBU_NOTIFY, 0, 0, 0, cxport, 0]:newbroker broker := CxBroker(nb, NIL) ActivateCxObj(broker, 1) signal := AllocSignal(-1) IF signal = -1 THEN Raise(NOSIG) NEW data data.task := FindTask(NIL) data.signal := Shl(1, signal) keyport := CreateMsgPort() keyreq := CreateIORequest(keyport, SIZEOF iostd) OpenDevice('keyboard.device', NIL, keyreq, NIL) NEW int int.ln.pri := 32 int.ln.name := rhd int.code := {handlercode} int.data := data keyreq.data := int keyreq.command := KBD_ADDRESETHANDLER DoIO(keyreq) installed := TRUE cxmask := Shl(1, cxport.sigbit) WHILE running recd := Wait(data.signal OR cxmask OR SIGBREAKF_CTRL_C OR SIGBREAKF_CTRL_D) IF recd AND data.signal IF listen IF av.shutdowncmd[] SystemTagList(av.shutdowncmd, [SYS_USERSHELL, TRUE, TAG_END]) IF av.wait[] THEN Delay(av.wait[] * 50) ENDIF IF av.warn THEN req(rhd, 'Warning: Your Amiga will\nreset in a few seconds!', 'Reset NOW') ENDIF keyreq.command := KBD_RESETHANDLERDONE DoIO(keyreq) -> Good-bye, old world, so long, farewell... it's been enough, see you in hell :-) Wait(0) -> just in case... ENDIF IF recd AND cxmask WHILE msg := GetMsg(cxport) msgid := CxMsgID(msg) msgtype := CxMsgType(msg) ReplyMsg(msg) IF msgtype = CXM_COMMAND SELECT msgid CASE CXCMD_DISABLE ActivateCxObj(broker, 0) listen := FALSE CASE CXCMD_ENABLE ActivateCxObj(broker, 1) listen := TRUE CASE CXCMD_KILL running := FALSE CASE CXCMD_UNIQUE running := FALSE -> start it again to remove it ENDSELECT ENDIF ENDWHILE ENDIF IF recd AND (SIGBREAKF_CTRL_C OR SIGBREAKF_CTRL_D) THEN running := FALSE ENDWHILE Raise(OK) handlercode: -> a1 points to data MOVE.L 4(A1),D0 -> get data.signal MOVE.L (A1),A1 -> get data.task MOVE.L A6,-(A7) -> save A6 MOVE.L $4.W,A6 -> get SysBase JSR Signal(A6) -> signal! MOVE.L (A7)+,A6 -> restore A6 /* MOVE.B $bfe001,D1 BCHG #1,D1 -> optionally blink the power LED MOVE.B D1,$bfe001 */ RTS EXCEPT SELECT exception CASE RDA PrintFault(IoErr(), myname) PutStr('$VER: ResetHandler 1.01 (15.12.95)\r\nby FtC of EfS\n') CASE "MEM" PutStr('Out of memory!\n') CASE "LIB" PutStr('Couldn''t open standard libraries... strange\n') CASE "DEV" PutStr('Couldn''t open keyboard.device!\n') CASE NOSIG PutStr('Couldn''t alloc a signal bit!\n') ENDSELECT IF rda THEN FreeArgs(rda) IF installed keyreq.data := int keyreq.command := KBD_REMRESETHANDLER DoIO(keyreq) ENDIF IF cxport THEN DeleteMsgPort(cxport) IF broker THEN DeleteCxObj(broker) IF keyreq IF keyreq.device THEN CloseDevice(keyreq) DeleteIORequest(keyreq) ENDIF IF keyport THEN DeleteMsgPort(keyport) IF cxbase THEN CloseLibrary(cxbase) IF iconbase THEN CloseLibrary(iconbase) IF signal THEN FreeSignal(signal) ENDPROC IF exception THEN 20 ELSE 0 PROC req(title : PTR TO CHAR, body : PTR TO CHAR, gadgets : PTR TO CHAR) DEF easy : easystruct easy.structsize := SIZEOF easystruct easy.flags := 0 easy.title := title easy.textformat := body easy.gadgetformat := gadgets EasyRequestArgs(NIL, easy, NIL, NIL) ENDPROC